package com.dengbw.systemtransfer.service;

import com.dengbw.systemtransfer.annotations.TimeSpeaker;
import com.dengbw.systemtransfer.global.Column;
import com.dengbw.systemtransfer.mapper.*;
import com.dengbw.systemtransfer.model.db.SysCorpStation;
import com.dengbw.systemtransfer.model.request.CunInfo;
import com.dengbw.systemtransfer.model.request.ZhenTransfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author dengbw
 * @date 2021/11/11 4:24 下午
 */
@Service
public class UpdateService {

    AgrAgriculturalMapper agrAgriculturalMapper;
    CmmCameraMapper cmmCameraMapper;
    CmmDeviceSignMapper cmmDeviceSignMapper;
    CmmFunctionCofigMapper cmmFunctionCofigMapper;
    CmmFunctionExtConfigMapper cmmFunctionExtConfigMapper;
    CmmLogUserMapper cmmLogUserMapper;
    CmmSignMapper cmmSignMapper;
    InfoConsultingBranchmemberMapper infoConsultingBranchmemberMapper;
    InfoConsultingMapper infoConsultingMapper;
    InfoConsultingRangeMapper infoConsultingRangeMapper;
    InfoConsultingStageMapper infoConsultingStageMapper;
    InfoGuidanceMapper infoGuidanceMapper;
    InfoHuinongMapper infoHuinongMapper;
    InfoLeadershipMapper infoLeadershipMapper;
    InfoNewsMapper infoNewsMapper;
    InfoOpenMapper infoOpenMapper;
    InfoReadcountMapper infoReadcountMapper;
    InfoRuralMapper infoRuralMapper;
    LedCadreMapper ledCadreMapper;
    NoticeInformationMapper noticeInformationMapper;
    NoticeInformationReaderMapper noticeInformationReaderMapper;
    NoticeInformationUserMapper noticeInformationUserMapper;
    NoticeLoudspeakersMapper noticeLoudspeakersMapper;
    NoticeLoudspeakersOrgMapper noticeLoudspeakersOrgMapper;
    NoticeLoudspeakersReaderMapper noticeLoudspeakersReaderMapper;
    NoticeLoudspeakersUserMapper noticeLoudspeakersUserMapper;
    NoticePhotographMapper noticePhotographMapper;
    ProEnterpriseMapper proEnterpriseMapper;
    ProInformationMapper proInformationMapper;
    ProPersonnelMapper proPersonnelMapper;
    ProTeamMapper proTeamMapper;
    PstFarmerBasicMapper pstFarmerBasicMapper;
    PstFarmerEducationMapper pstFarmerEducationMapper;
    PstFarmerExtConfigMapper pstFarmerExtConfigMapper;
    PstFarmerExtGroupMapper pstFarmerExtGroupMapper;
    PstFarmerHealthyMapper pstFarmerHealthyMapper;
    PstFarmerImpMapper pstFarmerImpMapper;
    PstFarmerIncomeMapper pstFarmerIncomeMapper;
    PstFarmerLabelMapper pstFarmerLabelMapper;
    PstFarmerMainMapper pstFarmerMainMapper;
    PstFarmerMapper pstFarmerMapper;
    PstFarmerPolicyMapper pstFarmerPolicyMapper;
    PstLabelMapper pstLabelMapper;
    ServeEntRecruitMapper serveEntRecruitMapper;
    SysBannerMapper sysBannerMapper;
    SysConfigMapper sysConfigMapper;
    SysCorpMapper sysCorpMapper;
    SysCorpStationMapper sysCorpStationMapper;
    SysCorpVillageMapper sysCorpVillageMapper;
    SysGroupMapper sysGroupMapper;
    SysHelpMapper sysHelpMapper;
    SysLabelMapper sysLabelMapper;
    SysLogMapper sysLogMapper;
    SysMenuMapper sysMenuMapper;
    SysOrgMapper sysOrgMapper;
    SysRoleMapper sysRoleMapper;
    SysRoleMenuMapper sysRoleMenuMapper;
    SysUserCorpMapper sysUserCorpMapper;
    SysUserExtRoleMapper sysUserExtRoleMapper;
    SysUserLockMapper sysUserLockMapper;
    SysUserLoginMapper sysUserLoginMapper;
    SysUserMapper sysUserMapper;
    SysUserRoleMapper sysUserRoleMapper;
    SysWxOpenMobileMapper sysWxOpenMobileMapper;
    UplFileMapper uplFileMapper;
    UplImageMapper uplImageMapper;

    @Autowired
    public UpdateService(AgrAgriculturalMapper agrAgriculturalMapper, CmmCameraMapper cmmCameraMapper, CmmDeviceSignMapper cmmDeviceSignMapper, CmmFunctionCofigMapper cmmFunctionCofigMapper, CmmFunctionExtConfigMapper cmmFunctionExtConfigMapper, CmmLogUserMapper cmmLogUserMapper, CmmSignMapper cmmSignMapper, InfoConsultingBranchmemberMapper infoConsultingBranchmemberMapper, InfoConsultingMapper infoConsultingMapper, InfoConsultingRangeMapper infoConsultingRangeMapper, InfoConsultingStageMapper infoConsultingStageMapper, InfoGuidanceMapper infoGuidanceMapper, InfoHuinongMapper infoHuinongMapper, InfoLeadershipMapper infoLeadershipMapper, InfoNewsMapper infoNewsMapper, InfoOpenMapper infoOpenMapper, InfoReadcountMapper infoReadcountMapper, InfoRuralMapper infoRuralMapper, LedCadreMapper ledCadreMapper, NoticeInformationMapper noticeInformationMapper, NoticeInformationReaderMapper noticeInformationReaderMapper, NoticeInformationUserMapper noticeInformationUserMapper, NoticeLoudspeakersMapper noticeLoudspeakersMapper, NoticeLoudspeakersOrgMapper noticeLoudspeakersOrgMapper, NoticeLoudspeakersReaderMapper noticeLoudspeakersReaderMapper, NoticeLoudspeakersUserMapper noticeLoudspeakersUserMapper, NoticePhotographMapper noticePhotographMapper, ProEnterpriseMapper proEnterpriseMapper, ProInformationMapper proInformationMapper, ProPersonnelMapper proPersonnelMapper, ProTeamMapper proTeamMapper, PstFarmerBasicMapper pstFarmerBasicMapper, PstFarmerEducationMapper pstFarmerEducationMapper, PstFarmerExtConfigMapper pstFarmerExtConfigMapper, PstFarmerExtGroupMapper pstFarmerExtGroupMapper, PstFarmerHealthyMapper pstFarmerHealthyMapper, PstFarmerImpMapper pstFarmerImpMapper, PstFarmerIncomeMapper pstFarmerIncomeMapper, PstFarmerLabelMapper pstFarmerLabelMapper, PstFarmerMainMapper pstFarmerMainMapper, PstFarmerMapper pstFarmerMapper, PstFarmerPolicyMapper pstFarmerPolicyMapper, PstLabelMapper pstLabelMapper, ServeEntRecruitMapper serveEntRecruitMapper, SysBannerMapper sysBannerMapper, SysConfigMapper sysConfigMapper, SysCorpMapper sysCorpMapper, SysCorpStationMapper sysCorpStationMapper, SysCorpVillageMapper sysCorpVillageMapper, SysGroupMapper sysGroupMapper, SysHelpMapper sysHelpMapper, SysLabelMapper sysLabelMapper, SysLogMapper sysLogMapper, SysMenuMapper sysMenuMapper, SysOrgMapper sysOrgMapper, SysRoleMapper sysRoleMapper, SysRoleMenuMapper sysRoleMenuMapper, SysUserCorpMapper sysUserCorpMapper, SysUserExtRoleMapper sysUserExtRoleMapper, SysUserLockMapper sysUserLockMapper, SysUserLoginMapper sysUserLoginMapper, SysUserMapper sysUserMapper, SysUserRoleMapper sysUserRoleMapper, SysWxOpenMobileMapper sysWxOpenMobileMapper, UplFileMapper uplFileMapper, UplImageMapper uplImageMapper) {
        this.agrAgriculturalMapper = agrAgriculturalMapper;
        this.cmmCameraMapper = cmmCameraMapper;
        this.cmmDeviceSignMapper = cmmDeviceSignMapper;
        this.cmmFunctionCofigMapper = cmmFunctionCofigMapper;
        this.cmmFunctionExtConfigMapper = cmmFunctionExtConfigMapper;
        this.cmmLogUserMapper = cmmLogUserMapper;
        this.cmmSignMapper = cmmSignMapper;
        this.infoConsultingBranchmemberMapper = infoConsultingBranchmemberMapper;
        this.infoConsultingMapper = infoConsultingMapper;
        this.infoConsultingRangeMapper = infoConsultingRangeMapper;
        this.infoConsultingStageMapper = infoConsultingStageMapper;
        this.infoGuidanceMapper = infoGuidanceMapper;
        this.infoHuinongMapper = infoHuinongMapper;
        this.infoLeadershipMapper = infoLeadershipMapper;
        this.infoNewsMapper = infoNewsMapper;
        this.infoOpenMapper = infoOpenMapper;
        this.infoReadcountMapper = infoReadcountMapper;
        this.infoRuralMapper = infoRuralMapper;
        this.ledCadreMapper = ledCadreMapper;
        this.noticeInformationMapper = noticeInformationMapper;
        this.noticeInformationReaderMapper = noticeInformationReaderMapper;
        this.noticeInformationUserMapper = noticeInformationUserMapper;
        this.noticeLoudspeakersMapper = noticeLoudspeakersMapper;
        this.noticeLoudspeakersOrgMapper = noticeLoudspeakersOrgMapper;
        this.noticeLoudspeakersReaderMapper = noticeLoudspeakersReaderMapper;
        this.noticeLoudspeakersUserMapper = noticeLoudspeakersUserMapper;
        this.noticePhotographMapper = noticePhotographMapper;
        this.proEnterpriseMapper = proEnterpriseMapper;
        this.proInformationMapper = proInformationMapper;
        this.proPersonnelMapper = proPersonnelMapper;
        this.proTeamMapper = proTeamMapper;
        this.pstFarmerBasicMapper = pstFarmerBasicMapper;
        this.pstFarmerEducationMapper = pstFarmerEducationMapper;
        this.pstFarmerExtConfigMapper = pstFarmerExtConfigMapper;
        this.pstFarmerExtGroupMapper = pstFarmerExtGroupMapper;
        this.pstFarmerHealthyMapper = pstFarmerHealthyMapper;
        this.pstFarmerImpMapper = pstFarmerImpMapper;
        this.pstFarmerIncomeMapper = pstFarmerIncomeMapper;
        this.pstFarmerLabelMapper = pstFarmerLabelMapper;
        this.pstFarmerMainMapper = pstFarmerMainMapper;
        this.pstFarmerMapper = pstFarmerMapper;
        this.pstFarmerPolicyMapper = pstFarmerPolicyMapper;
        this.pstLabelMapper = pstLabelMapper;
        this.serveEntRecruitMapper = serveEntRecruitMapper;
        this.sysBannerMapper = sysBannerMapper;
        this.sysConfigMapper = sysConfigMapper;
        this.sysCorpMapper = sysCorpMapper;
        this.sysCorpStationMapper = sysCorpStationMapper;
        this.sysCorpVillageMapper = sysCorpVillageMapper;
        this.sysGroupMapper = sysGroupMapper;
        this.sysHelpMapper = sysHelpMapper;
        this.sysLabelMapper = sysLabelMapper;
        this.sysLogMapper = sysLogMapper;
        this.sysMenuMapper = sysMenuMapper;
        this.sysOrgMapper = sysOrgMapper;
        this.sysRoleMapper = sysRoleMapper;
        this.sysRoleMenuMapper = sysRoleMenuMapper;
        this.sysUserCorpMapper = sysUserCorpMapper;
        this.sysUserExtRoleMapper = sysUserExtRoleMapper;
        this.sysUserLockMapper = sysUserLockMapper;
        this.sysUserLoginMapper = sysUserLoginMapper;
        this.sysUserMapper = sysUserMapper;
        this.sysUserRoleMapper = sysUserRoleMapper;
        this.sysWxOpenMobileMapper = sysWxOpenMobileMapper;
        this.uplFileMapper = uplFileMapper;
        this.uplImageMapper = uplImageMapper;
    }

    @TimeSpeaker("update deployed")
    @Transactional(rollbackFor = Exception.class)
    public void updateDeployed(ZhenTransfer zhenTransfer, CunInfo cunInfo) {
        String cunCorpId = cunInfo.getCorpId();
        String zhenCorpId = zhenTransfer.getZhenCorpId();
        Long cunSubId = cunInfo.getSubIdInZhen();
        agrAgriculturalMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        cmmCameraMapper.update(v -> v.set(Column.DING_CORP_ID, zhenCorpId).eq(Column.DING_CORP_ID, cunCorpId));
        cmmDeviceSignMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        cmmLogUserMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        cmmSignMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoConsultingBranchmemberMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoConsultingMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoConsultingRangeMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
//        infoConsultingStageMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoGuidanceMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoHuinongMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoLeadershipMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoNewsMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoOpenMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoReadcountMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        infoRuralMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        ledCadreMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        noticeInformationMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        noticeInformationReaderMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        noticeInformationUserMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        noticeLoudspeakersMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        noticeLoudspeakersOrgMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        noticeLoudspeakersReaderMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        noticeLoudspeakersUserMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).eq(Column.TENANT_ID, cunCorpId));
        noticePhotographMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        proEnterpriseMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        proInformationMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        proPersonnelMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        proTeamMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerBasicMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerEducationMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerExtConfigMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerExtGroupMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerHealthyMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerImpMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerIncomeMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerLabelMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerMainMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstFarmerPolicyMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        pstLabelMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        serveEntRecruitMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        sysBannerMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        List<SysCorpStation> stations = sysCorpStationMapper.queryList(v -> v.eq(Column.DING_CORP_ID, zhenCorpId).eq(Column.SUB_ID, cunSubId));
        if (CollectionUtils.isEmpty(stations)) {
            sysCorpStationMapper.update(v -> v.set(Column.DING_CORP_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.DING_CORP_ID, cunCorpId));
        }
//        sysCorpVillageMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, zhenCorpId));
        sysGroupMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        sysHelpMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        sysLabelMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        sysLogMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        sysUserCorpMapper.update(v -> v.set(Column.DING_CORP_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.DING_CORP_ID, cunCorpId));
        sysUserExtRoleMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        sysUserLockMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        sysUserMapper.update(v -> v.set(Column.DING_SYNC, 0).set(Column.DING_USER_ID, null).set(Column.DING_CORP_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.DING_CORP_ID, cunCorpId));
//        sysRoleMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        sysWxOpenMobileMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        uplFileMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
        uplImageMapper.update(v -> v.set(Column.TENANT_ID, zhenCorpId).set(Column.SUB_ID, cunSubId).eq(Column.TENANT_ID, cunCorpId));
    }
}
